package com.pignest.framework.json;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

/**
 * fix org.directwebremoting.json.types.JsonArray
 * */
public class JsonArray extends JsonValue implements List<JsonValue> {
	
	private final List<JsonValue> proxy;
	
	public JsonArray () {
		proxy = new ArrayList<JsonValue>();
	}
	@Override
	public String toExternalRepresentation() {
		StringBuffer output = new StringBuffer();
		output.append("[ ");

		boolean isFirst = true;
		for (JsonValue value : proxy) {
			if (isFirst) {
				isFirst = false;
			} else {
				output.append(", ");
			}

			output.append(value.toExternalRepresentation());
		}
		output.append(" ]");
		return output.toString();
	}

	@Override
	public boolean equals(Object o) {
		return proxy.equals(o);
	}

	@Override
	public int hashCode() {
		return proxy.hashCode();
	}

	public void add(int index, JsonValue value) {
		proxy.add(index, value);
	}

	public boolean add(JsonValue value) {
		return proxy.add(value);
	}
	
	public boolean add(String... values) {
		for (int i = 0; i < values.length; i++) {
			proxy.add(new JsonString(values[i]));
		}
		return true;
	}
	
	public boolean add(int value) {
		return proxy.add(new JsonNumber(value));
	}

	public boolean addAll(Collection<? extends JsonValue> collection) {
		return proxy.addAll(collection);
	}

	public boolean addAll(int index, Collection<? extends JsonValue> collection) {
		return proxy.addAll(index, collection);
	}

	public void clear() {
		proxy.clear();
	}

	public boolean contains(Object sought) {
		return proxy.contains(sought);
	}

	public boolean containsAll(Collection<?> collection) {
		return proxy.containsAll(collection);
	}

	public JsonValue get(int index) {
		return proxy.get(index);
	}

	public int indexOf(Object sought) {
		return proxy.indexOf(sought);
	}

	public boolean isEmpty() {
		return proxy.isEmpty();
	}

	public Iterator<JsonValue> iterator() {
		return proxy.iterator();
	}

	public int lastIndexOf(Object sought) {
		return proxy.lastIndexOf(sought);
	}

	public ListIterator<JsonValue> listIterator() {
		return proxy.listIterator();
	}

	public ListIterator<JsonValue> listIterator(int startIndex) {
		return proxy.listIterator(startIndex);
	}

	public JsonValue remove(int value) {
		return proxy.remove(value);
	}

	public boolean remove(Object value) {
		return proxy.remove(value);
	}

	public boolean removeAll(Collection<?> collection) {
		return proxy.removeAll(collection);
	}

	public boolean retainAll(Collection<?> collection) {
		return proxy.retainAll(collection);
	}

	public JsonValue set(int index, JsonValue value) {
		return proxy.set(index, value);
	}

	public int size() {
		return proxy.size();
	}

	public List<JsonValue> subList(int startIndex, int endIndex) {
		return proxy.subList(startIndex, endIndex);
	}

	public Object[] toArray() {
		return proxy.toArray();
	}

	public <T> T[] toArray(T[] toFill) {
		return proxy.toArray(toFill);
	}
}
